// 测试资源上限

#include <iostream>
#include <unistd.h>
#include <sys/resource.h>
#include <signal.h>

void handler(int signo)
{
    std::cout << "signo: " << signo << std::endl;
}

int main()
{
    for(int i = 1;i <= 31;i++)
    {
        signal(i, handler);
    }

    // 限制CPU资源上限
    // struct rlimit r;
    // r.rlim_cur = 1;
    // r.rlim_max = RLIM_INFINITY;
    // setrlimit(RLIMIT_CPU, &r);
    // while(1);

    // 限制占用内存上限
    struct rlimit r;
    r.rlim_cur = 1024 * 1024 * 40;
    r.rlim_max = RLIM_INFINITY;
    setrlimit(RLIMIT_AS, &r);

    int count = 1;
    while(1)
    {
        int *p = new int[1024*1024];
        std::cout << "size: " << count << std::endl;
        count++;
        sleep(1);
    }

    return 0;
}